package com.shop.config;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author yinxing
 * @date 2022-08-30
 */
@Component
@Slf4j
public class ShopMqConfig {

    @RabbitListener(queues = "${shop.queue}")
    public void receiveMessage(Message message , Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException {
        String msg= new String(message.getBody());
        log.info("==========接收到消息:{}=================",msg);
        if ("hello".equals(msg)){
            log.info("=============拒收hello================");
            channel.basicNack(deliveryTag,false,false);
        }
    }


}
